package com.wuliu.servlet;

import com.wuliu.dao.SecondImageDAO;
import com.wuliu.dao.impl.SecondImageDAOImpl;
import com.wuliu.model.SecondImage;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/admin/second_image/add")
public class AdminSecondImageAddServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String img=req.getParameter("img");
        SecondImageDAO secondImageDAO =new SecondImageDAOImpl();
        SecondImage secondImage =new SecondImage(null,img);
        secondImageDAO.update(secondImage);
        req.getRequestDispatcher("/WEB-INF/view/admin/second_image_add.jsp").forward(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String img=req.getParameter("img");
        SecondImageDAO secondImageDAO =new SecondImageDAOImpl();
        SecondImage secondImage =new SecondImage(null,img);
        secondImageDAO.add(secondImage);
        resp.sendRedirect("/admin/second_image");
    }
}
